package com.twu.biblioteca;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: mbokhari
 * Date: 11/07/2013
 * Time: 13:15
 * To change this template use File | Settings | File Templates.
 */
public class BookReserver implements MenuInterface {
    private Library library = new Library();
    private Notifier notifier = new Notifier();

    public BookReserver(Library library) {
        this.library = library;
    }

    public void runItems() throws IOException {
        notifier.printMessage("Please enter the title of the book you would like to reserve : \n>>");

        InputReader inputReader = new InputReader();
        String reservingTitle = inputReader.readUserInputString();

        reserveBook(reservingTitle);
    }

    public boolean reserveBook(String title) {
        for (Book book : library.returnAllBooksInLibrary()) {
            if (book.getTitle().equals(title)) {
                book.reserveBook();
                return true;
            }
        }
        notifier.displayBookNotFound(title);
        return false;
    }
}
